package com.yunxitest.yunxitest.item.ethernet

import android.content.Context
import android.content.IntentFilter
import android.net.ConnectivityManager
import com.yunxitest.yunxitest.Interface.IDetectItem
import com.yunxitest.yunxitest.Interface.IResultCallback

class EthernetDetectManager(val context: Context,var callback: IResultCallback) : IDetectItem {
    private val mEthernetBroadcastReceiver = EthernetBroadcastReceiver(callback)
    /**
     * 注册以太网路的广播
     */
    private fun registerEthernetReceiver() {
        val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
        intentFilter.addAction("android.net.wifi.STATE_CHANGE")
        intentFilter.addAction("android.Net.wifi.WIFI_STATE_CHANGED")
        context.registerReceiver(mEthernetBroadcastReceiver, intentFilter)
    }

    override fun startDetect() {
//        ShellUtils.execCmd("echo 0 > /sys/class/gpios-ctrl/usb_ctrl", false)
        registerEthernetReceiver()
        mEthernetBroadcastReceiver.startReceive()
    }

    override fun finish() {
        context.unregisterReceiver(mEthernetBroadcastReceiver)
    }
}